Telegram Group & Telegram Channel
7. Program to Calculate Area's.

import java.util.Scanner;

class AreaCalculator
{

float l, b, h, r, ba, s, c;
float result = 0f;
float pi = 3.14f;
int var;
public static void main(String[] args)
{
AreaCalculator ar = new AreaCalculator();
ar.options();
}

public void options()
{
Scanner a = new Scanner(System.in);
System.out.println("Enter the Object of which Area is to be calculated \n1:square \n2:rectangle \n3:Triangle\n4:circle\n5:Trapezoid\n6:Repeat\n7:Exit");

var = a.nextInt();
Area a1 = new Area();

if (var == 1)
{
System.out.println("Enter the Side of Square");
s = a.nextFloat();
a1.square(s);
options();
}

else if (var == 2)
{
System.out.println("Enter the Length of Rectangle");
l = a.nextFloat();
System.out.println("Enter the Breadth of Rectangle");
b = a.nextFloat();
a1.rectangle(l, b);
options();
}

else if (var == 3)
{
System.out.println("Enter the Height of Triangle");
h = a.nextFloat();
System.out.println("Enter the Base of Triangle");
ba = a.nextFloat();
a1.triangle(h, ba);
options();
}

else if (var == 4)
{
System.out.println("Enter the Radius of Circle");
r = a.nextFloat();
a1.circle(r);
options();
}

else if (var == 5)
{
System.out.println("Enter the A side of Trapezoid");
b = a.nextFloat();
System.out.println("Enter the B side of Trapezoid");
c = a.nextFloat();
System.out.println("Enter the Height of Trapezoid");
h = a.nextFloat();
a1.trapezoid(b, c, h);
options();
}
}
}

class Area
{
public void square(float s)
{
float result = 0f;
result = s * s;
System.out.println("The Area of Square is :" + result);
}

public void rectangle(float l, float b)
{
float result = 0f;
result = l * b;
System.out.println("The Area of Rectangle is :" + result);
}

public void triangle(float h, float ba)
{
float result = 0f;
result = 0.5f * h * ba;
System.out.println("The Area of Triangle is :" + result);
}

public void circle(float r)
{
float result = 0f;
result = 3.14f * (r * r);
System.out.println("The Area of Circle is :" + result);
}

public void trapezoid(float b, float c, float h)
{
float result = 0f;
result = (((b + c) / 2) * h);
System.out.println("The Area of Trapezoid is :" + result);
}
}

@java_codings



tg-me.com/java_codings/11
Create:
Last Update:

7. Program to Calculate Area's.

import java.util.Scanner;

class AreaCalculator
{

float l, b, h, r, ba, s, c;
float result = 0f;
float pi = 3.14f;
int var;
public static void main(String[] args)
{
AreaCalculator ar = new AreaCalculator();
ar.options();
}

public void options()
{
Scanner a = new Scanner(System.in);
System.out.println("Enter the Object of which Area is to be calculated \n1:square \n2:rectangle \n3:Triangle\n4:circle\n5:Trapezoid\n6:Repeat\n7:Exit");

var = a.nextInt();
Area a1 = new Area();

if (var == 1)
{
System.out.println("Enter the Side of Square");
s = a.nextFloat();
a1.square(s);
options();
}

else if (var == 2)
{
System.out.println("Enter the Length of Rectangle");
l = a.nextFloat();
System.out.println("Enter the Breadth of Rectangle");
b = a.nextFloat();
a1.rectangle(l, b);
options();
}

else if (var == 3)
{
System.out.println("Enter the Height of Triangle");
h = a.nextFloat();
System.out.println("Enter the Base of Triangle");
ba = a.nextFloat();
a1.triangle(h, ba);
options();
}

else if (var == 4)
{
System.out.println("Enter the Radius of Circle");
r = a.nextFloat();
a1.circle(r);
options();
}

else if (var == 5)
{
System.out.println("Enter the A side of Trapezoid");
b = a.nextFloat();
System.out.println("Enter the B side of Trapezoid");
c = a.nextFloat();
System.out.println("Enter the Height of Trapezoid");
h = a.nextFloat();
a1.trapezoid(b, c, h);
options();
}
}
}

class Area
{
public void square(float s)
{
float result = 0f;
result = s * s;
System.out.println("The Area of Square is :" + result);
}

public void rectangle(float l, float b)
{
float result = 0f;
result = l * b;
System.out.println("The Area of Rectangle is :" + result);
}

public void triangle(float h, float ba)
{
float result = 0f;
result = 0.5f * h * ba;
System.out.println("The Area of Triangle is :" + result);
}

public void circle(float r)
{
float result = 0f;
result = 3.14f * (r * r);
System.out.println("The Area of Circle is :" + result);
}

public void trapezoid(float b, float c, float h)
{
float result = 0f;
result = (((b + c) / 2) * h);
System.out.println("The Area of Trapezoid is :" + result);
}
}

@java_codings

BY Advance Java πŸ‘¨β€πŸ’»


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/java_codings/11

View MORE
Open in Telegram


Advance Java ‍ Telegram | DID YOU KNOW?

Date: |

What is Telegram?

Telegram is a cloud-based instant messaging service that has been making rounds as a popular option for those who wish to keep their messages secure. Telegram boasts a collection of different features, but it’s best known for its ability to secure messages and media by encrypting them during transit; this prevents third-parties from snooping on messages easily. Let’s take a look at what Telegram can do and why you might want to use it.

The Singapore stock market has alternated between positive and negative finishes through the last five trading days since the end of the two-day winning streak in which it had added more than a dozen points or 0.4 percent. The Straits Times Index now sits just above the 3,060-point plateau and it's likely to see a narrow trading range on Monday.

Advance Java ‍ from vn


Telegram Advance Java πŸ‘¨β€πŸ’»
FROM USA